package kr.moiba.user.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import kr.moiba.user.dao.UserDao;
import kr.moiba.user.domain.User;
import kr.moiba.user.service.UserSvc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Lee Youngho
 *
 */

@Service
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT ,rollbackFor = {Exception.class} ,readOnly = false)
public class UserSvcImpl implements UserSvc {

	@Autowired
	UserDao userDao;
	
	public UserSvcImpl() {
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public User findbyAuth(String userId) throws Exception {
		// TODO Auto-generated method stub
		return userDao.selectAuth(userId);
	}

	@Override
	public List<User> findbyList(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		return (List<User>) (userDao.SelectList(condition));
	}

	public Map<String, Object> findbyListPaging(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("userList", (List<User>) (userDao.SelectList(condition)));
		resultMap.put("userListTotalCnt", (Integer) (userDao.SelectListTotalCnt(condition)));
		
		return resultMap;
	}

	@Override
	public User findby(Integer idx) throws Exception {
		// TODO Auto-generated method stub
		return userDao.select(idx);
	}

	@Override
	public User add(User user) throws Exception {
		// TODO Auto-generated method stub
		User result = userDao.insert(user);
		
		return result;
	}

	@Override
	public User modify(User user) throws Exception {
		// TODO Auto-generated method stub
		return userDao.update(user);
	}

	@Override
	public int remove(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		return userDao.delete(condition);
	}
	
	@Override
	public int reuse(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		return userDao.undelete(condition);
	}

	@Override
	public String findbyChkDupl(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		
		String result = "true";
		Integer cnt = (Integer) (userDao.SelectListTotalCnt(condition));
		if(cnt != null && cnt == 0){
			result = "false";
		}
		
		return result;
	}

}